package com.ltl.keep_book.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ltl.keep_book.mapper.ItemTypeMapper;
import com.ltl.keep_book.model.dto.ItemTypeDTO;
import com.ltl.keep_book.model.po.ItemTypePO;
import com.ltl.keep_book.service.ItemTypeService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class ItemTypeServiceImpl extends ServiceImpl<ItemTypeMapper, ItemTypePO>
        implements ItemTypeService {


    @Override
    public int edit(ItemTypeDTO itemTypeDTO) {
        ItemTypePO itemTypePO = new ItemTypePO();
        itemTypePO.setItemLevel(itemTypeDTO.getItemLevel());
        itemTypePO.setItemName(itemTypeDTO.getItemName());
        itemTypePO.setItemParentId(itemTypeDTO.getItemParentId());
        itemTypePO.setUpdateTime(LocalDateTime.now());
        if (ObjectUtil.isEmpty(itemTypeDTO.getId())) {
            //新增
            itemTypePO.setCreateTime(LocalDateTime.now());
            return this.baseMapper.insert(itemTypePO);
        } else {
            //编辑
            itemTypePO.setId(itemTypeDTO.getId());
            return this.baseMapper.updateById(itemTypePO);
        }
    }
}
